package com.mrd.modules.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mrd.modules.system.entity.SysUserEntity;
import com.mrd.modules.system.service.SysUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mrd.base.utils.PageUtils;
import com.mrd.base.utils.Query;
import com.mrd.base.utils.R;


/**
 * 用户表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-07-12 11:01:14
 */
@RestController
@RequestMapping("sysuser")
public class SysUserController {
	@Autowired
	private SysUserService sysUserService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		PageHelper.startPage(query.getPage(),query.getLimit());
		List<SysUserEntity> sysUserList = sysUserService.queryList(query);
    	PageInfo<SysUserEntity> pi = new PageInfo<SysUserEntity>(sysUserList);
		PageUtils pageUtil = new PageUtils(sysUserList, Integer.parseInt(pi.getTotal()+""), query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		SysUserEntity sysUser = sysUserService.queryObject(id);
		
		return R.ok().put("sysUser", sysUser);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody SysUserEntity sysUser){
		sysUserService.save(sysUser);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody SysUserEntity sysUser){
		sysUserService.update(sysUser);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Integer[] ids){
		sysUserService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
